import { LayerID } from "../../common/config/GameUIConfig";
import { GameManager, debounce } from "../game/GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameTurntable extends cc.Component {

    @property(cc.Node)
    wheel: cc.Node = null;

    isInrate = false;

    // onLoad () {}

    start() {
        this.isInrate = false;
    }

    @debounce(200)
    click_rotate() {
        if (this.isInrate) return;
        this.isInrate = true;
        let degree = -60; // 旋转停止的角度

        switch (GameManager.getInstance().gameData.gameOverType) {
            case 0:
                degree = 0;
                break;
            case 1:
                degree = -120;
                break;
            case 2:
                degree = (Math.random() >= 0.5) ? -180 : 120;
                break;
            case 3:
                degree = -60;
                break;

        }

        let time = 3; //旋转时间
        let circle = 10; //旋转圈数
        cc.tween(this.wheel)
            .to(time, { angle: 360 * circle + degree }, { easing: 'sineInOut' })
            .delay(1)
            .call(() => {
                // this.reward.getChildByName("num").getComponent(cc.Label).string = "" + turnData.num;
                // this.reward.active = true;
                GameManager.getInstance().ui.openView(LayerID.gameReward);
                GameManager.getInstance().ui.removeView(LayerID.gameTurntable);
            })
            .start()

    }

    clickClose() {
        // GameManager.getInstance().ui.removeView(LayerID.gameTurntable);
    }

    // update (dt) {}
}
